// http://api.my531.com/GetMsg/?token=登录返回的token&id=项目ID&phone=手机号码
import axios from "axios"
import { toFail, toSuccess } from "@sker/core"
import { z } from "zod"
import { useAddonSetting, useData } from "@sker/runtime"


export default async () => {
    const input = z.object({
        phone: z.string(),
        type: z.string()
    })
    const body = input.parse(useData())
    let id = `31915`
    if (body.type === '1') {
        id = `31915`
    }
    const coreSetting = await useAddonSetting(`@autojs/core`)
    if (!coreSetting) return toFail(`操作失败`)
    const token = coreSetting.smsToken;
    // 19277916174
    const url = `http://api.my531.com/GetMsg/?token=${token}&id=${id}&phone=${body.phone}&type=json`
    return axios.get(url).then(res => res.data).then(res => {
        if (res.stat) {
            return toSuccess(res.data)
        } else {
            return toFail(res.message)
        }
    })
}